#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from base.Sequence import Sequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
from gpgpu.Utils import LoopControl


#  This test verifies that a standard loop executes for the expected number
#  of iterations.
class MainSequence(Sequence):
    def generate(self, **kargs):
        gpr_index = self.getRandomGPR(exclude="0")
        gpr_name = "x%d" % gpr_index
        self.reserveRegister(gpr_name)

        orig_gpr_val = self.random32()
        self.initializeRegister(gpr_name, orig_gpr_val)

        loop_control = LoopControl(self.genThread)
        loop_control.start(LoopCount=3)

        self.genInstruction("ADDI##CALM", {"rd": gpr_index, "rs1": gpr_index, "simm12": 1})

        loop_control.end()

        (gpr_val, valid) = self.readRegister(gpr_name)
        if not valid:
            self.error("Unable to read register %s" % gpr_name)

        expected_gpr_val = orig_gpr_val + 3
        if gpr_val != expected_gpr_val:
            # self.error('Unexpected register value: Expected = 0x%x,
            #            Actual = 0x%x' % (expected_gpr_val, gpr_val))
            pass


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
